/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.text.SimpleDateFormat;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import model.Task;

/**
 *
 * @author Luci
 */
class TaskCell implements ListCellRenderer{
    private TaskCellPanel cell = new TaskCellPanel();
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

        //JPopupMenu menu = new JPopupMenu();
        //JMenuItem item = new JMenuItem("Done");
        //menu.add(item);
        cell.setPanel((Task) value);
        cell.isSelected(isSelected);
        return cell;
        
    }
    
}
class TaskCellPanel extends JPanel{
    
    private JLabel lbName = new JLabel();
    private JLabel lbNote = new JLabel();
    private final static SimpleDateFormat sdf = new SimpleDateFormat(" dd-MM-yyyy   HH:mm");
    
    private JLabel dateStart = new JLabel();
    private JLabel dateEnd = new JLabel();
    public TaskCellPanel(){
        
    }
    public void setPanel(Task task){
        //this.removeAll();
        setSize(500,100);
        setOpaque(true);
        setVisible(true);
        lbName.setText(task.getName());
        lbName.setIcon(new ImageIcon(task.getIconStatus()));
        lbName.setHorizontalAlignment(JLabel.LEFT);
        add(lbName);
        lbName.setPreferredSize(new Dimension(150,50));
        
        lbNote.setText(task.getNote());
        lbNote.setIcon(new ImageIcon(task.getIconPriority()));
        lbNote.setHorizontalAlignment(JLabel.RIGHT);
        //lbNote = new JLabel(task.getNote(), new ImageIcon(task.getIconPriority()), JLabel.RIGHT);
        
        add(lbNote);
        
        dateStart.setText("Bắt đầu: "+sdf.format(task.getDateStart()));
        dateEnd.setText("Kết thúc: "+sdf.format(task.getDateEnd()));
        add(dateStart);
        add(dateEnd);
        setLayout(new FlowLayout());
        setToolTipText(task.getDescription());
        
    }
    public void isSelected(boolean is){
        if(is){
                setBackground(new Color(0, 0, 128));
                setForeground(Color.white);
                
            }else{
                setBackground(Color.white);
                setForeground(Color.black);
            }
    }
    
    
}
